package org.ourgrid.broker.business.scheduler.workqueue.xmlcreator;

public class XMLUtils {

	public static String toValidXML(String string) {
		
		if (string == null) {
			return null;
		}
		
		StringBuilder builder = new StringBuilder();
		for (char current : string.toCharArray()) {
			if ((current == 0x9) ||
	                (current == 0xA) ||
	                (current == 0xD) ||
	                ((current >= 0x20) && (current <= 0xD7FF)) ||
	                ((current >= 0xE000) && (current <= 0xFFFD)) ||
	                ((current >= 0x10000) && (current <= 0x10FFFF))) {
				builder.append(current);
			}
		}
		
		return builder.toString();
	}

}
